package com.alibaba.sample.kantiezi.web.user.module.screen;

import com.alibaba.biz.command.Command;
import com.alibaba.biz.command.CommandSupport;
import com.alibaba.biz.command.dispatcher.CommandDispatcher;
import com.alibaba.biz.command.result.Result;
import com.alibaba.sample.kantiezi.dal.dataobject.User;
import com.alibaba.sample.kantiezi.web.common.auth.PetstoreUser;
import com.alibaba.service.template.TemplateContext;
import com.alibaba.turbine.module.screen.TemplateScreen;
import com.alibaba.turbine.service.rundata.RunData;
import com.alibaba.webx.WebxException;

public abstract class Account extends TemplateScreen {
    protected abstract CommandDispatcher getCommandDispatcher();

    protected void execute(RunData rundata, TemplateContext context)
            throws WebxException {
        Command command = new CommandSupport("viewUser");

        command.getParameters().put("userId", PetstoreUser.getCurrentUser().getId());

        Result result = getCommandDispatcher().execute(command);

        if (result.isSuccess()) {
            User user = (User) result.getDefaultModel();

            context.put("user", user);
        }
    }
}
